package com.android.nearshop.app.adapter.listadapter;


import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.android.nearshop.R;
import com.android.nearshop.app.widget.AdvView;
import com.android.nearshop.business.cache.DataCacheManager;
import com.android.nearshop.io.protocol.out.Adv;
import com.android.nearshop.util.NotifyListener;

/*********************************************************
 * @author : zhaohua
 * @version : 2012-8-16
 * @see : 广告图片列表适配器
 * @Copyright : copyrights reserved by personal 2007-2011
 **********************************************************/
public class AdvListAdapter extends ArrayListAdapter<Adv>
{
    private LayoutInflater mInflater;
    
    public AdvListAdapter(Context context)
    {
        super(context);
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        convertView = mInflater.inflate(R.layout.view_image, null);
        AdvView advView = (AdvView)convertView.findViewById(R.id.image);
        advView.bindData((Adv)getItem(position));
        return convertView;
    }
    
    public void loadMainAdvs()
    {
        DataCacheManager.getInstance().getMainAdvs(new NotifyListener<List<Adv>>()
        {
            @Override
            public void onSucceed(List<Adv> result)
            {
                if(result != null)
                {
                    setList(result);
                }
            }
            
            @Override
            public void onError(int resultCode)
            {
                // do nothings ...
            }
        },false);
    }
}
